package com.briup.jz.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.AccountCustomer;
import com.briup.jz.bean.AccountCustomerExample;
import com.briup.jz.bean.AccountSystem;
import com.briup.jz.bean.AccountSystemExample;
import com.briup.jz.dao.AccountSystemMapper;
import com.briup.jz.service.AccountSystemService;
import com.briup.jz.utils.CustomerException;
@Service
public class AccountSystemServiceImpl  implements AccountSystemService{
	@Autowired
	private AccountSystemMapper accountsystemMapper;

	@Override
	public void saveOrUpdate(AccountSystem accountsystem) throws CustomerException {
		// TODO Auto-generated method stub
		
		if(accountsystem.getId()!=null) {
			accountsystemMapper.updateByPrimaryKey(accountsystem);
		}else {
			// 判断是否有同名，如果有抛出异常
//			AccountSystemExample example = new AccountSystemExample();
//			example.createCriteria().andIdEqualTo(AccountSystem.getId());
//			List<AccountSystem> list = accountsystemMapper.selectByExample(example);
//			if(list.size()>0) {
//				throw new CustomerException("同名已存在");
//			初始化
			accountsystem.setTransferTime((new Date().getTime()));
			accountsystem.setStatus("正常");
			accountsystemMapper.insert(accountsystem);
			}
	}
	
	@Override
	public List<AccountSystem> query(Long id,String status,String type) {
		/*模板*/
		AccountSystemExample example=new AccountSystemExample();
		/*条件查询*/
		AccountSystemExample.Criteria criteria = example.createCriteria();
		if(id!=null) {
			criteria.andIdEqualTo((long)id);
		}
		if(status!=null) {
			criteria.andStatusEqualTo(status);
		}
		if(type!=null) {
			criteria.andTypeEqualTo(type);
		}
		List<AccountSystem> list = accountsystemMapper.selectByExample(example);
	/*	for(AccountSystem a:list) {
			System.out.println(a);
		}
		System.out.println("zzzzzz");*/
		return list;
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		// TODO Auto-generated method stub
		AccountSystem address=accountsystemMapper.selectByPrimaryKey(id);
		if(address==null) {
			throw new CustomerException("要删除不存在");
		}
		accountsystemMapper.deleteByPrimaryKey(id);
	}

}
